package entity;

import server.HttpServlet;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 封装Host，每一个host下可以有多个context（web应用）
 */
public class Host {
    private String name;
    private String appbase;
    //存放应用的数组
    private List<Context> contexts = new ArrayList<>();


    /**
     * 获取当前host下所有的servlet
     * @return
     */
    public HashMap<String, HttpServlet> getServletMappings(){
        HashMap<String, HttpServlet> result = new HashMap<>();
        //将所有context下的servlet合并
        contexts.forEach(context -> {
            Map<String, HttpServlet> servletMappings = context.getServletMappings();
            result.putAll(servletMappings);
        });
        return result;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAppbase() {
        return appbase;
    }

    public void setAppbase(String appbase) {
        this.appbase = appbase;
    }

    public List<Context> getContexts() {
        return contexts;
    }

    public void setContexts(List<Context> contexts) {
        this.contexts = contexts;
    }
}

